import 'package:enterprise_v6_app/app/components/custom_refresh.dart';
import 'package:enterprise_v6_app/app/components/unit_selection/internal_unit/internal_unit_controller.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';
import 'package:enterprise_v6_app/app/data/entities/application/department_entity.dart';

/// 内部单位
class InternalUnitPage extends StatelessWidget {
  InternalUnitPage({required this.isRadio, super.key});

  /// 是否单选
  final bool isRadio;
  final controller = Get.put(InternalUnitController());

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(left: 16.w, right: 16.w, top: 10.w),
      alignment: Alignment.topCenter,
      color: const Color(0xffF5F5F6),
      child: CustomEasyRefreshList<DepartmentEntity>(
        isShowSearch: true,
        dataLoad: (pageIndex, pageSize, {String? search}) async {
          return controller.getDate(search: search);
        },
        enableLoad: false,
        itemBuilder: (DepartmentEntity item, int index) {
          return Container(
              padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 16.w),
              decoration: item.getIsChecked()
                  ? BoxDecoration(
                      borderRadius: BorderRadius.circular(8.w),
                      gradient: const LinearGradient(
                          //渐变位置
                          begin: Alignment.centerLeft,
                          end: Alignment.centerRight,
                          //渐变颜色[始点颜色, 结束颜色]
                          colors: [Color(0xff3B62FF), Color(0xff9FB2FF)]))
                  : BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(8.w)),
              child: Row(
                children: [
                  item.getIsChecked()
                      ? SvgPicture.asset(
                          AppImages.icon_unit_select,
                          width: 28.w,
                          height: 28.w,
                        )
                      : SvgPicture.asset(
                          AppImages.icon_unit_un_select,
                          width: 28.w,
                          height: 28.w,
                        ),
                  AppGaps.hGap12,
                  Text(
                    item.getShowName(),
                    style: TextStyle(
                        color: item.getIsChecked() ? const Color(0xffffffff) : const Color(0xff262F38),
                        height: 1.2,
                        fontWeight: FontWeight.w400,
                        fontSize: 16.sp),
                  ),
                ],
              )).clickOnce(() {
            controller.unitSelectionController.onTap(item, isRadio);
          });
        },
      ),
    );
  }
}
